//创建一个路由器并暴露出去
//引入
import { createRouter, createWebHistory } from "vue-router";
//引入一个个要呈现的组件
import Home from "../新学习Vue文件夹/生命周期/Home.vue";
import News from "../新学习Vue文件夹/生命周期/News.vue";
import About from "../新学习Vue文件夹/生命周期/About.vue";
import Detail from "../新学习Vue文件夹/生命周期/Detail.vue";
//创建
const router = createRouter({
  history: createWebHistory(), //路由器的工作模式
  routes: [
    {
      name: "zhuye",
      path: "/home",
      component: Home,
    },

    {
      name: "xinwen",
      path: "/news",
      component: News,
      children: [
        {
          name: "xiangxi",
          path: "detail",
          component: Detail,
          //第一种写法：将路由收到的所有params参数作为prop传给路由组件
          // props: true,

          //第二种写法：函数写法，可以自己决定将什么作为props给路由组件
          props(route) {
            return route.query;
          },
          //第三种写法：对象写法
          //   props:{
          //     a:100,b:200,c:300
          //   }
        },
      ],
    },

    {
      name: "guanyu",
      path: "/about",
      component: About,
    },
    //重定向
    {
      path: "/",
      redirect: "/home",
    },
  ],
});
//暴露出去
export default router;
